layui.config({
    base: '/plugins/module/'
});
layui.use(['table', 'layer', 'form', 'cstmodules','laydate'], function () {

    var mymod = layui.cstmodules;
    var $ = layui.jquery;
    var table = layui.table;
    var layer = layui.layer;
    var form = layui.form;
    var laydate=layui.laydate;

    //初始化时间选择器
    laydate.render({
        elem:'#startTime',
        type:'datetime'
    });
    laydate.render({
        elem:'#endTime',
        type:'datetime'
    });

    // 渲染表格
    var sysmgr = {
        param: {
            tableColumn: [
                [
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID', align: 'center'},
                    {field: 'userId', title: '用户ID', align: 'center'},
                    {field: 'time', title: '请求时间', align: 'center'},
                    {field: 'url', title: '请求路径', align: 'center'},
                    {field: 'describe', title: '请求描述', align: 'center'},
                    {field: 'describeType', title: '请求描述类型', align: 'center'},
                    {field: 'typeName', title: '请求类型名称', align: 'center'},
                    {field: 'ip', title: '请求的ip地址', align: 'center'},
                    {field: 'parameter', title: '请求参数', align: 'center'},
                    {field: 'methods', title: '请求方法', align: 'center'},
                    {field: 'abnormal', title: '异常', align: 'center'},
                    {templet: '#menuRowBar', align: 'center', title: '操作'}
                ]
            ],
            mainIndex: null,
            url: null,
            limit: 15,
            limits: [15, 30, 60, 120]
        },
        //删除
        deleteMenu: function (data) {
            $.ajax(
                {
                    url: "/sys/d/sysLog",
                    data: {"ids": data},
                    type: "post",
                    dataType: "json",
                    success: function (data) {
                        if (data.code == 1) {
                            layer.msg(data.info, {
                                time: 1000
                            }, function () {
                                table.reload('menuTable');
                            });
                        } else {
                            layer.alert(data.msg);
                        }
                    },
                    error: function () {
                        layer.alert("操作异常！请联系管理员");
                    }
                });
        }
    }
    mymod.initPageTableMethod(table, "menuTable", "/sys/f/sysLog", sysmgr.param.tableColumn, "#menuToolBar", null, sysmgr.param.limit, sysmgr.param.limits, 130);

    //监听工具条
    table.on('tool(menuTable)', function (obj) {
        var data = obj.data;
        switch (obj.event) {
            case 'delete':
                layer.confirm('你确定要删除这些日志数据吗?', {icon: 3, title: '提示'}, function (index) {
                    var ids = new Array();
                    ids.push(data.id);
                    sysmgr.deleteMenu(ids);

                });
                break;
        };
    });

    //监听头部工具栏
    table.on('toolbar(menuTable)', function (obj) {
        switch (obj.event) {
            case 'batchdelte':
                var checkStatus = table.checkStatus('menuTable')
                    , data = checkStatus.data;

                layer.confirm('你确定要删除这些日志数据吗?', {icon: 3, title: '提示'}, function (index) {
                    var ids = new Array();
                    for (var i = 0; i < data.length; i++) {
                        ids.push(data[i].id);
                    }
                    sysmgr.deleteMenu(ids);
                });
                break;
        };
    });

    //模糊查询
    form.on("submit(doSearch)", function (data) {
        var data1 = data.field;
        if(data1.userId == ""){
            data1.userId = 0;
        }
        table.reload('menuTable', {
            where: data.field,
            page: {
                curr: 1
            }
        });
        return false;
    });

});
